package handler

import (
	"encoding/json"
	"log"

	"github.com/olahol/melody"
)

type OrderExpired struct{}

func (oe OrderExpired) SendMessage(ws *melody.Melody, session *melody.Session, msg []byte) {
	ws.BroadcastFilter(msg, func(q *melody.Session) bool {
		message := map[string]interface{}{}
		json.Unmarshal(msg, &message)
		log.Println("session =", session)
		log.Println("q =", q)
		log.Println("oid =", message["oid"])
		// 发送给指定客户端,获取消息中的目标用户(客户端)与每个用户进行对比
		// 当匹配成功即可发送到目标用户(客户端)
		// return message["to_uid"] == q.Request.URL.Query().Get("from_uid")
		return true
	})
}
